<template>
  <a-form
    :model="formState"
    name="basic"
    :label-col="{ span: 8 }"
    :wrapper-col="{ span: 16 }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <CustomInput v-model:age="formState.age" v-model="formState.username"></CustomInput>

    <a-form-item label="没有name">
      <a-input v-model:value="formState.title" />
    </a-form-item>

    <a-form-item
      label="Password"
      name="password"
      :rules="[{ required: true, message: 'Please input your password!' }]"
    >
      <a-input-password v-model:value="formState.password" />
    </a-form-item>

    <a-form-item name="remember" :wrapper-col="{ offset: 8, span: 16 }">
      <a-checkbox v-model:checked="formState.remember">Remember me</a-checkbox>
    </a-form-item>

    <a-form-item :wrapper-col="{ offset: 8, span: 16 }">
      <a-button type="primary" html-type="submit">Submit</a-button>
    </a-form-item>
  </a-form>
  <div>form最后的结果：{{ JSON.stringify(formState) }}</div>
</template>
<script lang="ts" setup>
import { reactive } from 'vue'
import CustomInput from './CustomInput.vue'

interface FormState {
  username: string
  password: string
  remember: boolean
  age?: number
  title: string
}

const formState = reactive<FormState>({
  username: '',
  password: '',
  remember: true,
  age: 10,
  title: ''
})
const onFinish = (values: any) => {
  console.log('Success:', values)
}

const onFinishFailed = (errorInfo: any) => {
  console.log('Failed:', errorInfo)
}
</script>
